package com.library.lockConsumer.cabinet;

import com.library.lockProvider.pojo.Cabinet.CabinetResult;
import com.library.lockProvider.service.CabinetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;


@RestController
@RequestMapping("/api/Cabinet")
public class CabinetController {

    @Autowired
    CabinetService cabinetService;

    //说明书3.1，查询是否在线
    @GetMapping("/CheckIsOnline")
    @ResponseBody
    public String checkIsOnline(int cabinetId) throws UnsupportedEncodingException {
        return cabinetService.checkIsOnline(cabinetId);
    }

    //说明书3.2 设置设备名称
    @GetMapping("/SetCabinetName")
    @ResponseBody
    public CabinetResult setCabinetName(int cabinetId,String cabinetName){

        return cabinetService.set_deviceName(cabinetId,cabinetName);
    }

    //说明书3.3 设置二维码
    @GetMapping("/Set_qrParam")
    @ResponseBody
    public CabinetResult set_qrParam(int cabinetId,String qrCode){
        return  cabinetService.set_qrParam(cabinetId,qrCode);
    }

    //说明书3.4 设置设备文本显示信息
    @GetMapping("/SetTextView")
    @ResponseBody
    public CabinetResult setTextView(int cabinetId,String text1,String text2,String text3){
        return cabinetService.set_text(cabinetId,text1,text2,text3);
    }

    //说明书3.5 设置设备箱门总数
    @GetMapping("/SetBoxCount")
    @ResponseBody
    public CabinetResult setBoxCount(int cabinetID,int boxCount,long timeStamp,String sign){
        return null;
    }

    //说明书3.6 设置设备语音是否开关
    @GetMapping("/SetVoiceSwitch")
    @ResponseBody
    public CabinetResult setVoiceSwitch(int cabinetID,boolean isOpen,long timeStamp,String sign){
        return null;
    }


    //说明书3.7 查询箱门状态
    @GetMapping("/CheckChannelState")
    @ResponseBody
    public CabinetResult checkChannelState(int cabinetId,int boxNo){
        return cabinetService.get_boxInfo(cabinetId,boxNo);
    }


    //说明书3.8 打开指定箱门
    @GetMapping("/OpenOneBox")
    @ResponseBody
    public CabinetResult openOneBox(String s_id){
        return cabinetService.openOneBox(s_id);
    }


    //说明书3.9 打开所有箱门
    @GetMapping("/OpenAllBox")
    @ResponseBody
    public CabinetResult openAllBox(int cabinetId){
        return cabinetService.openAllBox(cabinetId);
    }

    //说明书3.10 打开指定箱门并清空密码
    @GetMapping("/ClearOneBox")
    @ResponseBody
    public CabinetResult clearOneBox(int cabinetId,int boxNo,int optType,int isOpen){
        return cabinetService.clearOneBox(cabinetId,boxNo,optType,isOpen);
    }


    //说明书3.11 打开所有箱门并清空所有密码
    @GetMapping("/ClearAllBox")
    @ResponseBody
    public CabinetResult clearAllBox(int cabinetId){
        return cabinetService.clearAllBox(cabinetId);
    }

    //说明书3.12 设定开箱密码
    @GetMapping("/SetOpenCode")
    @ResponseBody
    public CabinetResult setOpenCode(int cabinetId, int boxNo, String openCode11, String pwd,int effectFlag, int isOpen){
        return cabinetService.setOpenCode(cabinetId,boxNo,openCode11,pwd,effectFlag,isOpen);
    }


}
